package com.springcloud.framework.servicea.service;

import com.springcloud.framework.servicea.dao.UserRepository;
import com.springcloud.framework.servicea.entity.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.*;
import org.springframework.stereotype.Service;

import javax.persistence.EntityManager;

/**
 * TODO
 *
 * @author zhanggm
 * @date 2021/4/26 10:03
 */
@Service
public class UserService {

    @Autowired
    private UserRepository userRepository;

    @Autowired
    private EntityManager entityManager;

    public Page<UserEntity> getPageInfo(UserEntity userEntity, Integer pageNum, Integer pageSize) {
        Example example = Example.of(userEntity,ExampleMatcher.matching().withMatcher("name",ExampleMatcher.GenericPropertyMatchers.contains()));
        Pageable pageable = PageRequest.of(pageNum - 1, pageSize, Sort.Direction.DESC, "id");
        Page all = userRepository.findAll(example, pageable);
        return all;
    }

}
